<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="f" uri="/WEB-INF/tags/functions.tld" %>
<%@ taglib prefix="t" uri="/WEB-INF/tags/tags.tld" %>
<link rel="stylesheet" href="/css/table.css" type="text/css" media="all" />
<link rel="stylesheet" href="/css/paging.css" type="text/css" media="all" />
<link rel="stylesheet" href="/css/message.css" type="text/css" media="all" />
<script type="text/javascript" src="/js/functions.js"></script>
<script type="text/javascript" src="/js/notify.js"></script>

<h2 style="margin-left: 2%;">Danh sách sinh viên lớp ${currentClass.classId}</h2>
<hr size="1" />

<div class="box">
	<h3 class="boxTitle">Chọn lớp</h3>
	<form action="/lecturer/listStudentsInClass.html" method="GET">
		<table style="width: 100%" align="center">
			<tr>
				<td>Mã lớp</td>
				<td>
					<select name="key">
						<option value="NONE">-- Chọn lớp --</option>
						<c:forEach items="${classes}" var="c">
							<c:if test="${f:keyToString(c.classKey) == param.key}">
								<option value="${f:keyToString(c.classKey)}" selected="selected">${c.classId} - ${c.className}</option>
							</c:if>
							<c:if test="${f:keyToString(c.classKey) != param.key}">
								<option value="${f:keyToString(c.classKey)}">${c.classId} - ${c.className}</option>
							</c:if>
						</c:forEach>
					</select>
				</td>
			</tr>
			<tr>
				<td colspan="2"><input type="submit" value="Tìm kiếm" /></td>
			</tr>
		</table>
	</form>
</div>

<c:if test="${msg != null}">
	<div class="notify">
		<c:out value="${msg}" />
	</div>
	<c:remove var="msg" scope="session"/>
</c:if>

<c:if test="${students == null or empty students}">
	<c:choose>
		<c:when test="${param.key == null || param.key == '' || param.key == 'NONE'}">
			<b>Chọn một lớp</b>
		</c:when>
		<c:otherwise>
			<b>Không có sinh viên nào</b>
		</c:otherwise>
	</c:choose>
</c:if>
<c:if test="${students != null and !empty students}">
	<form action="/lecturer/deleteStudentsInClass.html?p=${pageInfo.currentPage}&key=${param.key}" method="post">
		<table>
			<thead>
				<tr>
					<td class="th" style="width: 1em;"><input type="checkbox" name="checkAll" id="checkAll" /></td>
					<th class="th">STT</th>
					<th class="th">Mã sinh viên</th>	
					<th class="th">Tên sinh viên</th>
					<th class="th">Email</th>
					<th class="th">Tên lớp</th>
					<th class="th">Khóa</th>
					<th class="th">Xóa</th>
				</tr>	
			</thead>
			<tbody>
			<c:forEach items="${students}" var="s" varStatus="status">
				<tr>
					<td class="td" style="width: 1em;"><input type="checkbox" name="checkItem" value="${f:keyToString(s.studentKey)}" /></td>
					<td class="td"><c:out value="${(pageInfo.currentPage - 1) * pageSize + status.count}" escapeXml="true" /></td>
					<td class="td"><c:out value="${s.studentId}" escapeXml="true" /></td>
					<td class="td"><c:out value="${s.studentName}" escapeXml="true" /></td>
					<td class="td"><c:out value="${s.studentEmail}" escapeXml="true" /></td>
					<td class="td"><c:out value="${s.className}" escapeXml="true" /></td>
					<td class="td"><c:out value="${s.course}" escapeXml="true" /></td>
					<c:url value="/lecturer/deleteStudentInClass/${f:keyToString(s.studentKey)}.html" var="deleteUrl">
						<c:param name="p" value="${pageInfo.currentPage}" />
						<c:param name="key" value="${param.key}" />
					</c:url>
					<td class="td"><a href="${deleteUrl}" class="deleteLink"><img src="/images/delete.png" width="15" height="15" /></a></td>
				</tr>
			</c:forEach>
			</tbody>
			<tfoot>
				<tr>
					<td colspan="8">
						<div class="pages">
							<t:paging pageInfo="${pageInfo}" link="/lecturer/listStudentsInClass.html" params="${params}" />
						</div>
						<input type="submit" value="Xóa" id="deleteGroup" disabled="disabled" style="margin-top: 1em; width: 4em" />
					</td>
				</tr>
			</tfoot>
		</table>
	</form>
</c:if>